﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace DoAn_BumTruong_DesignPattern
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);
            CreateUserWizard1.CreatedUser += CreateUserWizard1_CreatedUser;
        }

        void CreateUserWizard1_CreatedUser(object sender, EventArgs e)
        {
            try
            {
                //Lay user nguoi dung vua dang ky
                string namelogin = CreateUserWizard1.UserName;
                //Sau khi dang ky thanh cong thi tai khoan vao Roles (AcountCustomers)
                Roles.AddUserToRole(namelogin, "AcountCustomers");
                FormsAuthentication.SetAuthCookie(namelogin, false);
                string continueUrl = CreateUserWizard1.ContinueDestinationPageUrl;
                if (String.IsNullOrEmpty(continueUrl))
                {
                    continueUrl += "~/";
                }
                Response.Redirect(continueUrl);
            }
            catch (Exception)
            {
                throw;
            }
        }
    }
}